styleproperty: Move resolving code
authorBenjamin Otte <otte@redhat.com>
Tue, 31 May 2011 14:51:38 +0000 (16:51 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 2 Jun 2011 00:03:52 +0000 (02:03 +0200)
Also, resolving now always succeeds - if it doesn't we fall back to the
default value right here, instead of later.

gtk/gtkstyleproperties.c
gtk/gtkstyleproperty.c
gtk/gtkstylepropertyprivate.h

index 45fdfbd8d50838fffcd76046033bc841f4420591..6cf497390cea55c0cca5b43ee2cfc92426441332 100644 (file)
@@ -633,121 +633,6 @@ gtk_style_properties_set (GtkStyleProperties *props,
   va_end (args);
 }
 
-static gboolean
-resolve_color (GtkStyleProperties *props,
-              GValue             *value)
-{
-  GdkRGBA color;
-
-  /* Resolve symbolic color to GdkRGBA */
-  if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
-    return FALSE;
-
-  /* Store it back, this is where GdkRGBA caching happens */
-  g_value_unset (value);
-  g_value_init (value, GDK_TYPE_RGBA);
-  g_value_set_boxed (value, &color);
-
-  return TRUE;
-}
-
-static gboolean
-resolve_color_rgb (GtkStyleProperties *props,
-                   GValue             *value)
-{
-  GdkColor color = { 0 };
-  GdkRGBA rgba;
-
-  if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
-    return FALSE;
-
-  color.red = rgba.red * 65535. + 0.5;
-  color.green = rgba.green * 65535. + 0.5;
-  color.blue = rgba.blue * 65535. + 0.5;
-
-  g_value_unset (value);
-  g_value_init (value, GDK_TYPE_COLOR);
-  g_value_set_boxed (value, &color);
-
-  return TRUE;
-}
-
-static gboolean
-resolve_gradient (GtkStyleProperties *props,
-                  GValue             *value)
-{
-  cairo_pattern_t *gradient;
-
-  if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
-    return FALSE;
-
-  /* Store it back, this is where cairo_pattern_t caching happens */
-  g_value_unset (value);
-  g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
-  g_value_take_boxed (value, gradient);
-
-  return TRUE;
-}
-
-static gboolean
-resolve_shadow (GtkStyleProperties *props,
-                GValue *value)
-{
-  GtkShadow *resolved, *base;
-
-  base = g_value_get_boxed (value);
-
-  if (base == NULL)
-    return TRUE;
-  
-  if (_gtk_shadow_get_resolved (base))
-    return TRUE;
-
-  resolved = _gtk_shadow_resolve (base, props);
-  if (resolved == NULL)
-    return FALSE;
-
-  g_value_take_boxed (value, resolved);
-
-  return TRUE;
-}
-
-static gboolean
-style_properties_resolve_type (GtkStyleProperties     *props,
-                               const GtkStyleProperty *node,
-                               GValue                 *val)
-{
-  if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
-    {
-      if (node->pspec->value_type == GDK_TYPE_RGBA)
-        {
-          if (!resolve_color (props, val))
-            return FALSE;
-        }
-      else if (node->pspec->value_type == GDK_TYPE_COLOR)
-        {
-          if (!resolve_color_rgb (props, val))
-            return FALSE;
-        }
-      else
-        return FALSE;
-    }
-  else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
-    {
-      g_return_val_if_fail (node->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN, FALSE);
-
-      if (!resolve_gradient (props, val))
-        return FALSE;
-    }
-  else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
-    {
-      if (!resolve_shadow (props, val))
-        return FALSE;
-    }
-
-  return TRUE;
-}
-
 /* NB: Will return NULL for shorthands */
 const GValue *
 _gtk_style_properties_peek_property (GtkStyleProperties      *props,
@@ -780,10 +665,10 @@ _gtk_style_properties_peek_property (GtkStyleProperties      *props,
     return NULL;
 
   val = property_data_match_state (prop, state);
-
-  if (val &&
-      !style_properties_resolve_type (props, node, val))
+  if (val == NULL)
     return NULL;
+  
+  _gtk_style_property_resolve (node, props, val);
 
   return val;
 }
index 6458c83f8fed1380102a6cceb5b38d45006d63b6..811560349445798ab41e1b4f90ab196f570602cf 100644 (file)
@@ -1949,6 +1949,119 @@ _gtk_style_property_is_inherit (const GtkStyleProperty *property)
   return property->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
 }
 
+static gboolean
+resolve_color (GtkStyleProperties *props,
+              GValue             *value)
+{
+  GdkRGBA color;
+
+  /* Resolve symbolic color to GdkRGBA */
+  if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
+    return FALSE;
+
+  /* Store it back, this is where GdkRGBA caching happens */
+  g_value_unset (value);
+  g_value_init (value, GDK_TYPE_RGBA);
+  g_value_set_boxed (value, &color);
+
+  return TRUE;
+}
+
+static gboolean
+resolve_color_rgb (GtkStyleProperties *props,
+                   GValue             *value)
+{
+  GdkColor color = { 0 };
+  GdkRGBA rgba;
+
+  if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
+    return FALSE;
+
+  color.red = rgba.red * 65535. + 0.5;
+  color.green = rgba.green * 65535. + 0.5;
+  color.blue = rgba.blue * 65535. + 0.5;
+
+  g_value_unset (value);
+  g_value_init (value, GDK_TYPE_COLOR);
+  g_value_set_boxed (value, &color);
+
+  return TRUE;
+}
+
+static gboolean
+resolve_gradient (GtkStyleProperties *props,
+                  GValue             *value)
+{
+  cairo_pattern_t *gradient;
+
+  if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
+    return FALSE;
+
+  /* Store it back, this is where cairo_pattern_t caching happens */
+  g_value_unset (value);
+  g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
+  g_value_take_boxed (value, gradient);
+
+  return TRUE;
+}
+
+static gboolean
+resolve_shadow (GtkStyleProperties *props,
+                GValue *value)
+{
+  GtkShadow *resolved, *base;
+
+  base = g_value_get_boxed (value);
+
+  if (base == NULL)
+    return TRUE;
+  
+  if (_gtk_shadow_get_resolved (base))
+    return TRUE;
+
+  resolved = _gtk_shadow_resolve (base, props);
+  if (resolved == NULL)
+    return FALSE;
+
+  g_value_take_boxed (value, resolved);
+
+  return TRUE;
+}
+
+void
+_gtk_style_property_resolve (const GtkStyleProperty *property,
+                             GtkStyleProperties     *props,
+                             GValue                 *val)
+{
+  if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
+    {
+      if (property->pspec->value_type == GDK_TYPE_RGBA)
+        {
+          if (!resolve_color (props, val))
+            _gtk_style_property_resolve (property, props, val);
+        }
+      else if (property->pspec->value_type == GDK_TYPE_COLOR)
+        {
+          if (!resolve_color_rgb (props, val))
+            _gtk_style_property_resolve (property, props, val);
+        }
+      else
+        _gtk_style_property_resolve (property, props, val);
+    }
+  else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
+    {
+      g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN);
+
+      if (!resolve_gradient (props, val))
+        _gtk_style_property_resolve (property, props, val);
+    }
+  else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
+    {
+      if (!resolve_shadow (props, val))
+        _gtk_style_property_resolve (property, props, val);
+    }
+}
+
 gboolean
 _gtk_style_property_is_shorthand  (const GtkStyleProperty *property)
 {
index dab6f07af0dbf56d88329bcd0ebfa09c6190d7c4..afa76be616ef7adf1ec5f287cfeda9d644ed9b52 100644 (file)
@@ -73,6 +73,10 @@ void                     _gtk_style_property_default_value (const GtkStyleProper
                                                             GtkStyleProperties     *properties,
                                                             GValue                 *value);
 
+void                     _gtk_style_property_resolve       (const GtkStyleProperty *property,
+                                                            GtkStyleProperties     *properties,
+                                                            GValue                 *value);
+
 gboolean                 _gtk_style_property_is_shorthand  (const GtkStyleProperty *property);
 GParameter *             _gtk_style_property_unpack        (const GtkStyleProperty *property,
                                                             const GValue           *value,